package asteroids.entity;

import java.awt.Graphics;

import asteroids.engine.GameState;
import asteroids.entity.equipment.Equipment;
import asteroids.entity.weapon.Weapon;

/**
 * Given to a Ship as the Special. Can be given either a Weapon or an Equipment
 * in its constructor. If a Weapon is passed, triggering the special will invoke
 * Weapon.FIRE(); If an Equipment is passed, triggering the special will invoke
 * Equipment.update(GameState)
 * 
 * @author whitecd1
 * 
 */
public class SpecialAdapter extends Equipment
{
    Weapon weapon;
    Equipment equipment;
    boolean isWeapon;
    boolean engaged = false;

    public SpecialAdapter(Weapon weapon)
    {
        super(weapon.getOwner());
        this.weapon = weapon;
        isWeapon = true;
    }

    public SpecialAdapter(Equipment equipment)
    {
        super(equipment.getOwner());
        this.equipment = equipment;
        isWeapon = false;
    }

    public void respawn()
    {
        if( !isWeapon )
        {
            equipment.respawn();
        }
    }

    public void engage()
    {
        engaged = true;
    }

    public void update(GameState state)
    {
        if( engaged )
        {
            if( isWeapon )
            {
                weapon.FIRE(state);
            }
            else
            {
                equipment.update(state);
            }
        }
        engaged = false;
    }

    public void draw(Graphics g)
    {
        if( !isWeapon ) // weapons don't draw
        {
            equipment.draw(g);
        }
    }
}
